package com.sakila.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;


public class City implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -9219211884687252262L;
	
	private Integer id;
	@NotBlank
	private String name;
	@NotNull
	private Country country;
	private Date lastUpdate;
	@JsonIgnore
	private Set<Address> addresses = new HashSet<Address>();
	
	public City() {
		// TODO Auto-generated constructor stub
	}

	public City(String name, Date lastUpdate, Country country) {
		super();
		this.name = name;
		this.lastUpdate = lastUpdate;
		this.country = country;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public Set<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(Set<Address> addresses) {
		this.addresses = addresses;
	}
	
	public void addAddress(Address address){
		address.setCity(this);
		addresses.add(address);
	}
	
	public void removeAddress(Address address){
		address.setCity(null);
		addresses.remove(address);
	}
}
